# 理解打印顺序 有助于理解python 里各个类内部的对象的创建和调用逻辑
# https://pythontutor.com/
class F:
    def __init__(self, f):
        self.f = f

    def __call__(self, *args, **kwargs):
        # print("__call__" + self.f.__name__)
        aa = self.f(*args, **kwargs)
        # print(aa)
        # print("*******")
        return aa

    def __or__(self, other):
        # print("__or__" + self.f.__name__)
        ###################### 下面代码可以平替
        def xx(*args, **kwargs):
            xy = self(*args, **kwargs)
            xz = other(xy)
            return xz

        return F(xx)
        ##################################################
        # return F(lambda *args, **kwargs: other(self(*args, **kwargs)))


@F
def add_two(n):
    return n + 2


@F
def divide_3_floor(n):
    return n // 3


s = F(str)

k = add_two | divide_3_floor | s

k(7)
